package 力扣._100086_有序三元组中的最大值2;

public class Solution {
    public long maximumTripletValue(int[] nums) {
        int[] lmax = new int[nums.length];//左侧最大值
        int[] rmax = new int[nums.length];//右侧最大值
        int max = nums[0];
        for (int i = 0; i < nums.length - 1; i++) {
            max = Math.max(max, nums[i]);
            lmax[i+1] = max;
        }
        max = nums[nums.length - 1];
        for (int i = nums.length - 1; i > 0; i--) {
            max = Math.max(max, nums[i]);
            rmax[i-1] = max;
        }
        long t = 0;
        for (int i = 1; i < nums.length - 1; i++) {
            long t1 = (long) (lmax[i] - nums[i]) * rmax[i];
            t = Math.max(t, t1);
        }
        return t;
    }


    public static void main(String[] args) {
        int[] t = new int[]{10,13,6,2};
        long l = new Solution().maximumTripletValue(t);
        System.out.println(l);
    }
}
